<template>
	<view>
		<u-gap height="100rpx"></u-gap>
		<u-row customStyle="margin-bottom: 10px">
			<u-col span="4">
			</u-col>
			<u-col span="4">
				<u--image :showLoading="true" :src="logo" width="250rpx" height="250rpx"></u--image>
			</u-col>
			<u-col span="4">
			</u-col>
		</u-row>
		<u-gap height="100rpx"></u-gap>
		<u-row customStyle="margin-bottom: 10px">
			<u-col span="1">
			</u-col>
			<u-col span="10">
				<u--form labelPosition="left" :model="login_query" :rules="rules" ref="uForm">
					<u-form-item label="账号" prop="account" ref="item1">
						<u--input v-model="login_query.account" placeholder="输入手机号码" border="bottom"
							clearable></u--input>
					</u-form-item>
					<u-form-item label="密码" prop="password" ref="item1">
						<u--input type="password" v-model="login_query.password" placeholder="填写登陆密码" border="bottom"
							clearable></u--input>
					</u-form-item>
					<u-gap height="100rpx"></u-gap>
					<u-button @click="handleLogin" type="primary" size="large " text="登录" shape="circle"></u-button>
					<u-gap height="50rpx"></u-gap>
					<u-form-item>
						<u-row>
							<u-col span="2"></u-col>
							<u-col span="8">
								<u-radio-group v-model="agree">
									<u-radio shape="circle" name="1">
										<u--text text="已阅读并同意" size="12"></u--text>
										<u--text text="《用户协议》" size="12"></u--text>
										<u--text text="《隐私协议》" size="12"></u--text>
									</u-radio>
								</u-radio-group>
							</u-col>
							<u-col span="2"></u-col>
						</u-row>
					</u-form-item>
				</u--form>
			</u-col>
			<u-col span="1">
			</u-col>
		</u-row>
		<u-gap height="50rpx"></u-gap>
		<u-row>
			<u-col span="3"></u-col>
			<u-col span="7">
				<u--text text="◎2014-2023 www.crmeb.com" color="#999"></u--text>
			</u-col>
			<u-col span="2"></u-col>
		</u-row>
	</view>
</template>

<script>
	import { weixin } from '@/api/'
	export default {
		data() {
			return {
				logo: '',
				agree: '0',
				login_query: {
					account: '13176765939',
					password: 'xhx0219,',
				},
				rules: {
					account: [{ type: 'string', required: true, message: '请填写账号', trigger: ['blur', 'change'] }],
					password: [{ type: 'string', required: true, message: '请填写密码', trigger: ['blur', 'change'] }]
				}
			}
		},
		onLoad() {
			this.get_logo();
			var a = document.getElementsByClassName('uni-page-head-hd')[0]
			a.style.display = 'none';
		},
		methods: {
			//获取logo
			async get_logo() {
				let { status, data } = await weixin.get_logo_api();
				if (status === 200) {
					this.logo = data.logo_url;
				}
			},
			//登录
			handleLogin() {
				if (this.agree === '0') {
					uni.showToast({
						title: '请先阅读并同意协议',
						icon: 'none'
					})
				} else {
					this.$refs.uForm.validate().then(async (res) => {
						let { status, msg, data } = await weixin.login({ ...this.login_query });
						if (status === 200) {
							uni.setStorageSync('token', `Bearer ${data.token}`);
							let { status: info_status, data: info_data } = await weixin.uer_info();
							if (info_status === 200) {
								uni.setStorageSync('user_info', info_data);
							}
							//登陆成功跳转到前一个页面
							let pages = getCurrentPages();
							let page = pages[pages.length - 2];
							let router = '../' + page.route.substring(6);
							uni.switchTab({
								url: router
							});
						} else {
							uni.showToast({
								title: `msg`,
								icon: 'error'
							})
						}
					})
				}
			}
		}
	}
</script>

<style>
	.wrap {
		padding: 12px;
	}

	.demo-layout {
		height: 25px;
		border-radius: 4px;
	}

	.bg-purple {
		background: #CED7E1;
	}

	.bg-purple-light {
		background: #e5e9f2;
	}

	.bg-purple-dark {
		background: #99a9bf;
	}
</style>